home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / multitasking / feature / executive_v2.10 / sysinfo / oberon / source / sysinfo.mod next >
Text File  |  2000-03-02  |  10KB  |  271 lines

  1. (*(*
  2. **      $VER: SysInfo.h 2.00 (20.10.96)
  3. **      SysInfo Release 2.00
  4. **
  5. **      SysInfo.library definitions
  6. **
  7. **      This file is public domain.
  8. **
  9. **      Author: Petri Nordlund <petrin@megabaud.fi>
  10. **
  11. **      $Id: SysInfo.h 1.5 1996/10/01 23:03:07 petrin Exp petrin $
  12. **
  13. **      Oberon-Interface by Thomas Igracki (T.Igracki@Jana.berlinet.de)
  14. **
  15. **      20.10.96: Updated for v2
  16. *)*)
  17.  
  18. MODULE SysInfo;
  19. (* $StackChk- $RangeChk- $CaseChk- $OvflChk- $ReturnChk- $TypeChk- $NilChk- *)
  20. IMPORT
  21.    y: SYSTEM, e: Exec, I: Intuition;
  22.  
  23. CONST
  24.   name  * = "SysInfo.library"; minversion * = 1; version * = 2;
  25.  
  26. TYPE
  27.   SysInfoPtr          * = UNTRACED POINTER TO SysInfo;
  28.   LoadAveragePtr      * = UNTRACED POINTER TO LoadAverage;
  29.   NotifyPtr           * = UNTRACED POINTER TO Notify;
  30.   CpuUsagePtr         * = UNTRACED POINTER TO CpuUsage;
  31.   TaskCpuUsagePtr     * = UNTRACED POINTER TO TaskCpuUsage;
  32.  
  33. (*
  34.  * This structure is returned by InitSysInfo() and it's READ-ONLY.
  35.  *
  36.  * NOTE!! This structure will grow in the future, so don't make any assumptions
  37.  * about it's length.
  38.  *
  39.  *)
  40.  
  41.   SysInfo - = STRUCT 
  42. (* general *)
  43.      errNo -: LONGINT;        (* LONG: Used to hold error values   *)
  44.                               (*       from some functions         *)
  45. (* load average *)
  46.      loadAvgType  -: INTEGER; (* UWORD: load average type, see below       *)
  47.      loadAvgTime1 -: INTEGER; (* UWORD: Usually 1, 5 and 15 minutes.       *)
  48.      loadAvgTime2 -: INTEGER; (* UWORD: These times are in seconds.        *)
  49.      loadAvgTime3 -: INTEGER; (* UWORD: 0 = time not implemented           *)
  50.      fScale       -: INTEGER; (* UWORD: scale value, if lavgtype = FIXED   *)
  51.  
  52. (* id *)
  53.      pad1                : y.BYTE;  (* because BOOL = 2 Byte and BOOLEAN = 1 Byte! *)
  54.      getPpidImplemented -: BOOLEAN; (* BOOL: TRUE if GetPpid is implemented  *)
  55.      pad2                : y.BYTE;  (* because BOOL = 2 Byte and BOOLEAN = 1 Byte! *)
  56.      getPgrpImplemented -: BOOLEAN; (* BOOL: TRUE if GetPgrp is implemented  *)
  57.  
  58. (* get/setnice *)
  59.      whichImplemented -: SET;     (* UWORD: Search methods for Get/SetNice   *)
  60.      niceMin          -: INTEGER; (* WORD: Nice-value giving most cpu time   *)
  61.      niceMax          -: INTEGER; (* WORD: Nice-value giving least cpu time  *)
  62.  
  63. (* notify *)
  64.      pad3                  : y.BYTE;  (* because BOOL = 2 Byte and BOOLEAN = 1 Byte! *)
  65.      notifySigImplemented -: BOOLEAN; (* BOOL: Notify by signal implemented   *)
  66.      pad4                  : y.BYTE;  (* because BOOL = 2 Byte and BOOLEAN = 1 Byte! *)
  67.      notifyMsgImplemented -: BOOLEAN; (* BOOL: Notify by message implemented  *)
  68.  
  69. (* cpu usage *)
  70.      cpuUsageImplemented -: SET; (* UWORD: What cpu usage values are implemented *)
  71.  
  72. (* task cpu usage *)
  73.      taskCpuUsageImplemented -: SET; (* UWORD: What cpu usage values are implemented *)
  74.      reserved : ARRAY 8 OF LONGINT;  (* Reserved for future use *)
  75.   END;
  76.  
  77.  
  78. (*
  79.  * general
  80.  *
  81.  *)
  82.  
  83. CONST
  84. (* errno values *)
  85.   whichEPerm   * =  1;  (* Operation not permitted *)
  86.   whichESrch   * =  3;  (* No such process         *)
  87.   whichEAcces  * = 13;  (* Permission denied       *)
  88.   whichEInval  * = 22;  (* Invalid argument        *)
  89.  
  90.  
  91. (*
  92.  * load average
  93.  *
  94.  *)
  95.  
  96. (* Loadaverage type *)
  97.   loadAvgNone     * = 0;  (* load averages not implemented   *)
  98.   loadAvgFixedPnt * = 1;  (* load * SysInfo.fscale           *)
  99.  
  100. TYPE
  101. (* GetLoadAverage *)
  102.   LoadAverageFixed * = STRUCT 
  103.      load1 -: LONGINT; (* ULONG: *)
  104.      load2 -: LONGINT; (* ULONG: *)
  105.      load3 -: LONGINT; (* ULONG: *)
  106.   END;
  107.  
  108. (* This is needed when calling GetLoadAverage() *)
  109.   LoadAverage * = STRUCT
  110.      fixed - : LoadAverageFixed;
  111.      reserved: ARRAY 3 OF LONGINT; (* ULONG: Reserved for future use *)
  112.   END;
  113.  
  114. (*
  115.  * get/setnice
  116.  *
  117.  *)
  118.  
  119. CONST
  120. (* Possible search methods for Get/SetNice and are used in 'whichImplemented'-field *)
  121.   whichPrioProcess  * = 0;
  122.   whichPrioPgrp     * = 1;
  123.   whichPrioUser     * = 2;
  124.   whichPrioTask     * = 3;
  125.  
  126. (*
  127.  * notify
  128.  *
  129.  *)
  130.  
  131. TYPE
  132. (* This is needed when adding a notify-request. This may grow in future *)
  133.   Notify * = STRUCT 
  134.      port   -: e.MsgPortPtr;       (* struct MsgPort*: message port for notify-messages  *)
  135.      signal -: INTEGER;            (* WORD: signal NUMBER if you use signals  *)
  136.      reserved: ARRAY 2 OF LONGINT; (* LONG[2]: Reserved for future use *)
  137.   END;
  138.  
  139. (* Flags for AddNotify () *)
  140. CONST
  141.   anUseMessages * = 0;
  142.  
  143. (*
  144.  * cpu usage
  145.  *
  146.  *)
  147. TYPE
  148. (* This is needed when querying cpu usage *)
  149.   CpuUsage * = STRUCT 
  150.      totalUsedCpuTime      -: LONGINT; (* ULONG: Total used cputime in seconds      *)
  151.      totalElapsedTime      -: LONGINT; (* ULONG: Total used+idle cputime in seconds *)
  152.  
  153.      usedCpuTimeLastsec    -: LONGINT; (* ULONG: Used cputime during last second   *)
  154.      usedCpuTimeLastsecHz  -: LONGINT; (* ULONG: 100 * lastsec / lastsecHz = CPU % *)
  155.  
  156.      recentUsedCpuTime     -: LONGINT; (* ULONG: Recently used cputime             *)
  157.      recentUsedCpuTimeHz   -: LONGINT; (* ULONG: 100 * recent / hz = RECENT CPU %  *)
  158.      recentSeconds         -: INTEGER; (* UWORD: "recent" means this many seconds  *)
  159.  
  160.      involuntaryCSw        -: LONGINT; (* ULONG: Involuntary context switches *)
  161.      voluntaryCSw          -: LONGINT; (* ULONG: Voluntary context switches   *)
  162.      totalCSw              -: LONGINT; (* ULONG: Total # of context switches  *)
  163.  
  164.      involuntaryCSwLastsec -: LONGINT; (* ULONG: Involuntary csws during last second *)
  165.      voluntaryCSwLastsec   -: LONGINT; (* ULONG: Voluntary csws during last second   *)
  166.      totalCSwLastsec       -: LONGINT; (* ULONG: Total # of csws during last second  *)
  167.  
  168.      reserved : ARRAY 12 OF LONGINT; (* ULONG: Reserved for future use    *)
  169.   END;
  170.  
  171. CONST
  172. (* These bits are used in cpuUsageImplemented-field *)
  173.   cpuUsageTotalImplemented           * = 0;
  174.   cpuUsageLastsecImplemented         * = 1;
  175.   cpuUsageRecentImplemented          * = 2;
  176.   cpuUsageIvvoCSwImplemented         * = 3;
  177.   cpuUsageTotalCSwImplemented        * = 4;
  178.   cpuUsageIvvoCSwLastsecImplemented  * = 5;
  179.   cpuUsageTotalCSwLastsecImplemented * = 6;
  180.  
  181. (*
  182.  * task cpu usage
  183.  *
  184.  *)
  185.  
  186. TYPE
  187. (* This is needed when querying cpu usage of a task *)
  188.   TaskCpuUsage * = STRUCT 
  189.      totalUsedCpuTime      -: LONGINT; (* ULONG: Total used cputime                 *)
  190.      totalUsedTimeHz       -: LONGINT; (* ULONG: usedCputime / hz = cputime in secs *)
  191.      totalElapsedTime      -: LONGINT; (* ULONG: Total used+idle cputime in seconds *)
  192.  
  193.      usedCpuTimeLastsec    -: LONGINT; (* ULONG: Used cputime during last second    *)
  194.      usedCpuTimeLastsecHz  -: LONGINT; (* ULONG: 100 * lastsec / lastsec_hz = CPU % *)
  195.  
  196.      recentUsedCpuTime     -: LONGINT; (* ULONG: Recently used cputime             *)
  197.      recentUsedCpuTimeHz   -: LONGINT; (* ULONG: 100 * recent / hz = RECENT CPU %  *)
  198.      recentSeconds         -: INTEGER; (* UWORD: "recent" means this many seconds  *)
  199.  
  200.      involuntaryCSw        -: LONGINT; (* ULONG: Involuntary context switches *)
  201.      voluntaryCSw          -: LONGINT; (* ULONG: Voluntary context switches   *)
  202.      totalCSw              -: LONGINT; (* ULONG: Total # of context switches  *)
  203.  
  204.      involuntaryCSwLastsec -: LONGINT; (* ULONG: Involuntary csws during last second *)
  205.      voluntaryCSwLastsec   -: LONGINT; (* ULONG: Voluntary csws during last second   *)
  206.      totalCSwLastsec       -: LONGINT; (* ULONG: Total # of csws during last second  *)
  207.  
  208.      reserved : ARRAY 8 OF LONGINT; (* ULONG: Reserved for future use    *)
  209.   END;
  210.  
  211. CONST
  212. (* These bits are used in cpu_usage_implemented-field *)
  213.   taskCpuUsageTotalImplemented           * = 0;
  214.   taskCpuUsageLastsecImplemented         * = 1;
  215.   taskCpuUsageRecentImplemented          * = 2;
  216.   taskCpuUsageIvvoCSwImplemented         * = 3;
  217.   taskCpuUsageTotalCSwImplemented        * = 4;
  218.   taskCpuUsageIvvoCSwLastsecImplemented  * = 5;
  219.   taskCpuUsageTotalCSwLastsecImplemented * = 6;
  220.  
  221. VAR
  222.   base - : e.LibraryPtr;
  223.  
  224. (* -----init----- *)
  225. PROCEDURE InitSysInfo     * {base, -30} (): SysInfoPtr;
  226. PROCEDURE FreeSysInfo     * {base, -36} (si{8}: SysInfoPtr);
  227.  
  228. (* -----load average----- *)
  229. PROCEDURE GetLoadAverage  * {base, -42} (    si{8}: SysInfoPtr;
  230.                                          VAR la{9}: LoadAverage);
  231.  
  232. (* -----id----- *)
  233. PROCEDURE GetPid          * {base, -48} (si{8}: SysInfoPtr): LONGINT;
  234. PROCEDURE GetPpid         * {base, -54} (si{8}: SysInfoPtr): LONGINT;
  235. PROCEDURE GetPgrp         * {base, -60} (si{8}: SysInfoPtr): LONGINT;
  236.  
  237. (* -----nice----- *)
  238. PROCEDURE GetNice         * {base, -66} (si   {8}: SysInfoPtr;
  239.                                          which{0}: LONGINT;
  240.                                          who  {1}: LONGINT): LONGINT;
  241. PROCEDURE SetNice         * {base, -72} (si   {8}: SysInfoPtr;
  242.                                          which{0}: LONGSET;
  243.                                          who  {1}: LONGINT;
  244.                                          nice {2}: LONGINT): LONGINT;
  245.  
  246. (* -----notify----- *)
  247. PROCEDURE AddNotify       * {base, -78} (si         {8}: SysInfoPtr;
  248.                                          flags      {0}: SET;
  249.                                          safetyLimit{1}: LONGINT): NotifyPtr;
  250. PROCEDURE RemoveNotify    * {base, -84} (si    {8}: SysInfoPtr;
  251.                                          notify{9}: NotifyPtr);
  252.  
  253. (* -----cpu usage----- *)
  254. PROCEDURE GetCpuUsage     * {base, -90} (    si   {8}: SysInfoPtr;
  255.                                          VAR usage{9}: CpuUsage);
  256. PROCEDURE GetTaskCpuUsage * {base, -96} (    si   {8}: SysInfoPtr;
  257.                                          VAR usage{9}: TaskCpuUsage;
  258.                                              task{10}: e.TaskPtr): LONGINT;
  259.  
  260. BEGIN
  261.      base := e.OpenLibrary (name, minversion);
  262. (*
  263.      IF base = NIL THEN
  264.         IF I.DisplayAlert (I.recoveryAlert, "\x00\x64\x14missing SysInfo.library\o\o", 50) THEN END;
  265.         HALT (20)
  266.      END; (* IF *)
  267. *)
  268. CLOSE
  269.      IF base # NIL THEN e.CloseLibrary (base); base := NIL END (* IF *)
  270. END SysInfo.
  271.